layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    form.on("submit(btnSubmit)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        var itemDesc = editor.txt.html();
        var field = data.field;
        var type = field.type;
        var minPurchaseNum = field.minPurchaseNum;
        if (Number(minPurchaseNum) < 1){
            layer.alert("最小购买数不能小于1！")
            return false;
        }
        // 实际使用时的提交信息
        $.post("/item/updateOrAddEntity",{
            id : $("#id").val(),
            catId : $("#catId").val(),
            title : $("#title").val(),
            price : $("#price").val(),
            minPurchaseNum : minPurchaseNum,
            transferPrice : $("#transferPrice").val(),
            type : type,
            personNum : $("#personNum").val(),
            imageOne : $("#imageOne").val(),
            imageTwo : $("#imageTwo").val(),
            imageThree : $("#imageThree").val(),
            redeemCode : $("#redeemCode").val(),
            itemDesc : itemDesc
        },function(result){
            if(1==result.returnInfo.state){
                top.layer.close(index);
                top.layer.msg("操作成功！");
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            }else{
                top.layer.msg(result.returnInfo.errorMsg);
            }
        },"json")
        return false;
    });

    form.on('radio(type)', function(data){
        //console.log(data.elem); //得到radio原始DOM对象
        //console.log(data.value); //被点击的radio的value值
        if (data.value == '1'){
            $("#redeemCodeShow").hide();
            $("#redeemCode").val("");
        }else{
            $("#redeemCodeShow").show();
        }
    });
})